<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Template</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/ext/resources/css/ext-all.css"/>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/ext/resources/css/ext-icon.css"/>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/ext/resources/css/ext-revise.css"/>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/plugins/swfupload/css/icon.css"/>
<script type="text/javascript" src="<%=request.getContextPath()%>/ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/ext/ext-all.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/ext/ext-revise.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/ext/src/locale/ext-lang-zh_CN.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/plugins/swfupload/swfupload.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/plugins/swfupload/swfupload-dialog.js"></script>
<script type="text/javascript">
var typeId = "${typeId}";
var otherId = "${otherId}";
var atmtType = ${atmtType};
</script>
</head>

<body>
<script type="text/javascript">
Ext.onReady(function() {
    var dialog = new Ext.ux.SWFUploadDialog({
    	baseUrl: "<%=request.getContextPath()%>/plugins/",
        uploadMode: true,
        single: false,
        fileTypes: atmtType.typeScope,
        fileSizeLimit: atmtType.maxSize,
        fileUploadLimit: atmtType.maxTotal,
        postParams: {otherId: otherId, typeId: typeId},
        filePostName: "file",
        uploadUrl: "<%=request.getContextPath()%>/atmt/upload.do",
        removeUrl: "<%=request.getContextPath()%>/atmt/remove.do",
        downloadUrl: "<%=request.getContextPath()%>/atmt/download.do",
        fileUploadSuccess: function(file, json) {
            Ext.Msg.alert("Custom Handler for Upload Success", "RETURN DATA: " + json);
        }
    });
    
    new Ext.form.FieldSet({
        title: "SWFUpload Dialog",
        renderTo: Ext.getBody(),
        layout: "table",
        width: 350,
        layoutConfig: {
            column: 5
        },
        defaults: {
            xtype: "button",
            width: 100,
            style: "margin-right:10px"
        },
        items: [{
            text: "Upload",
            iconCls: "Upload",
            handler: function() {
                dialog.setUploadMode(true);
                dialog.show();
            }
        }, {
            text: "Download",
            iconCls: "Download",
            handler: function() {
                dialog.setUploadMode(false);
                dialog.show();
            }
        }, {
            text: "LoadFiles",
            iconCls: "Reload",
            handler: function() {
                Ext.Ajax.request({
                    url: "<%=request.getContextPath()%>/atmt/load.do",
                    params: {otherId: otherId, typeId: typeId},
                    method: "POST",
                    success: function(text) {
                        var json = Ext.util.JSON.decode(text.responseText);
                        if (json.success) {
                            dialog.loadUploadFile(json.files);
                        } else {
                            Ext.Msg.alert("消息框", "文件加载失败!");
                        }
                    },
                    failure: function(html) {}
                });
            }
        }]
    });
});
</script>
</body>
</html>
